package com.example.okhttputils.com.utils.base.interfaces;

import android.content.Context;
import android.os.Handler;

import java.util.Map;


/**
 * file description
 * Created by 72038967 on 2019/8/27.
 */
public class OKHttp {
    private static volatile Object mObject = new Object();

    private static OkHttpImp mOkHttpImp;

    private OKHttp() {

    }

    private static volatile OKHttp mOKHttp;

    public static OKHttp getInstance(Context context) {
        if (context == null) {
            throw new IllegalStateException("没有初始化");
        }
        if (mOKHttp == null) {
            synchronized (mObject) {
                mOKHttp = new OKHttp();

            }
        }
        if (mOkHttpImp == null) {
            mOkHttpImp = OkHttpImp.getInstance();

        }
        if (mOkHttpImp != null) {
            mOkHttpImp.setHandler(new Handler(context.getMainLooper()));

        }
        return mOKHttp;
    }

    /**
     * @param url
     * @param params
     * @param callback
     */
    public void doGet(String url, Map<String, String> params, ResponseCallBack callback) {
        OkHttpImp.getInstance().doGet(url, params, callback);

    }

    /**
     * @param url
     * @param params
     * @param callback
     */
    public void doPost(String url, Map<String, String> params, ResponseCallBack callback) {
        OkHttpImp.getInstance().doPost(url, params, callback);

    }

    /**
     * @param url
     * @param json
     * @param callBack
     */
    public void doPostJson(String url, String json, ResponseCallBack callBack) {

        OkHttpImp.getInstance().doPostJson(url, json, callBack);

    }

    public void downLoadImage(String url, ResponseCallBack callBack) {
        OkHttpImp.getInstance().downLoadImage(url, callBack);
    }
}
